home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / DB_CLIPP / 2510.ZIP / TRSOURCE.EXE / DEPVALDB.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  1KB  |  44 lines

  1. /*********
  2. *
  3. * DEPVALDB.C
  4. *
  5. * by Ralph Davis
  6. * modified by Tom Rettig
  7. *
  8. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  9. *
  10. *********/
  11.  
  12. /* DEPVALDB:  Depreciated value by declining-balance method
  13.    
  14.               Computes current value of an asset
  15.                 by declining balance method.
  16.  
  17.               Assumes fixed rate of depreciation per period.
  18.  
  19.               SYNTAX: DEPVALDB(value, rate, periods)
  20.                      where value   = current value
  21.                            rate    = rate of depreciation per period
  22.                            periods = number of periods elapsed
  23.  
  24.               RETURNS:  depreciated value at end of period.            
  25.  
  26.               Equation = value * (( 1 - rate)^periods)
  27. */
  28.  
  29. #include "trlib.h"
  30.  
  31. TRTYPE depvaldb()
  32. {
  33.    if ( PCOUNT==3 && ISNUM(1) && ISNUM(2) && ISNUM(3) )
  34.    {
  35.       double value   = _parnd(1);
  36.       double rate    = _parnd(2);
  37.       double periods = _parnd(3);
  38.  
  39.       _retnd(value * pow(1.0 - rate, periods));
  40.    }
  41.    else
  42.       _retnd( (double)ERROR );
  43. }
  44.